package com.yh.correct.service.impl;

import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.correct.dao.ICommunityAdminMapper;
import com.yh.correct.model.CommunityAdmin;
import com.yh.correct.model.Page;
import com.yh.correct.service.ICommunityAdminService;

/**
 * 作者:胡文恒
 * 创建时间:2017-03-08
 * 描述: 实现社区刑人员管理接口服务
 *
 */
@Service
public class CommunityAdminServiceImpl implements ICommunityAdminService {
	private static Logger logger = LogManager.getLogger(ExpireServiceImpl.class);
	@Autowired
	private ICommunityAdminMapper icam;
	/**
	 * 作者:胡文恒
	 * 创建时间:2017-03-08
	 * 描述: 添加服刑人员档案
	 * @throws Exception 
	 */
	@Override
	public int addCommunityAdmin(CommunityAdmin ca) throws Exception {
		// TODO Auto-generated method stub
		return icam.addCommunityAdmin(ca);
	}

	/**
	 * 作者:胡文恒
	 * 创建时间:2017-03-08
	 * 描述: 根据id查询服刑人员详细信息
	 * @throws Exception 
	 */
	@Override
	public Map getCommunityAdmin(CommunityAdmin ca) throws Exception {
		// TODO Auto-generated method stub
		return icam.getCommunityAdmin(ca);
	}

	/**
	 * 作者:胡文恒
	 * 创建时间:2017-03-08
	 * 描述: 根据id删除服刑人员详细信息
	 * @throws Exception 
	 */
	@Override
	public int delCommunityAdmin(CommunityAdmin ca) throws Exception {
		// TODO Auto-generated method stub
		return icam.delCommunityAdmin(ca);
	}

	/**
	 * 作者:胡文恒
	 * 创建时间:2017-03-08
	 * 描述: 模糊查询匹配的用户
	 * @throws Exception 
	 */
	@Override
	public Page getLikeAdminCount(Map<String, Object> cont) throws Exception {
		Page page = new Page();
		page.setTotalNum(icam.getLikeCommunityAdminCount(cont));
		int pageSize = Integer.parseInt(String.valueOf(cont.get("pageSize")));
		page.setPageSize(pageSize);
		int pageNum = Integer.parseInt(String.valueOf(cont.get("pageNum")));
		page.setCurPageNum(pageNum);
		page.setTotalPage(page.getTotalNum() / pageSize + (page.getTotalNum() % pageSize == 0 ? 0 : 1));
		page.setResult(icam.getALLCommunityAdmin(cont));
		return page;
	}

	/**
	 * 作者:胡文恒
	 * 创建时间:2017-03-15
	 * 描述: 查询下一个档案id
	 * @throws Exception 
	 */
	@Override
	public Integer getLastId() throws Exception{
		return icam.getLastId();
	}


	/**
	 * 作者:胡文恒
	 * 创建时间:2017-03-15
	 * 描述: 更新下载日期
	 * @throws Exception 
	 */
	@Override
	public Integer update(CommunityAdmin ca) throws Exception {
		// TODO Auto-generated method stub
		return icam.updateById(ca);
	}

	/**
	 * @author comcn155 修改档案
	 * @param ca
	 * @return
	 * @throws Exception
	 */
	@Override
	public int editCommunityAdmin(CommunityAdmin ca) throws Exception {
		return icam.editCommunityAdmin(ca);
	}

}
